home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / STDSTRBU.CC < prev    next >
C/C++ Source or Header  |  1992-03-30  |  3KB  |  69 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1992 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #pragma implementation "stdstrbuf.h"
  19. #include "ioprivate.h"
  20.  
  21. #include "ioconfig.h"
  22. #ifdef NAMES_HAVE_UNDERSCORE
  23. #define UNDERSCORE "_"
  24. #else
  25. #define UNDERSCORE ""
  26. #endif
  27.  
  28. // To avoid problems depending on constructor order (and for
  29. // efficiency) the standard streambufs (and streams) are
  30. // constructed statically using C-style '{ ... }' initializers.
  31. // Since you're not allowed to do this for structs that
  32. // have virtuals, we define fake streambuf and stream classes
  33. // that don't have any C++-isms, and initialize those.
  34. // To initialize the vtable field of the standard filebufs,
  35. // we use the expression 'vt_filebuf' which must evaluate to
  36. // (the address of) the virtual function table for the
  37. // filebuf class.
  38.  
  39. #if !defined(vt_filebuf)
  40. #ifndef __GNUG__
  41. // This works for cfront.
  42. #define vt_filebuf __vtbl__7filebuf
  43. extern char vt_filebuf[1];
  44. #elif defined(NO_DOLLAR_IN_LABEL)
  45. extern char vt_filebuf[1] asm(UNDERSCORE "_vt.filebuf");
  46. #else
  47. extern char vt_filebuf[1] asm(UNDERSCORE "_vt$filebuf");
  48. #endif
  49. #endif /* !defined(vt_filebuf) */
  50.  
  51. struct _fake_filebuf {
  52.     struct __streambuf s;
  53.     char* vtable;
  54.     struct __file_fields f;
  55. };
  56.  
  57. #define DEF_STD(NAME, FD, CHAIN, FLAGS) \
  58.     _fake_filebuf NAME[1] = {{\
  59.        { _IO_MAGIC+_S_IS_FILEBUF+FLAGS, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN},\
  60.        vt_filebuf, {0, 0, FD}}};
  61.  
  62. DEF_STD(_cin_sbuf, 0, 0, _S_CAN_READ);
  63. DEF_STD(_cout_sbuf, 1, (streambuf*)_cin_sbuf, _S_CAN_WRITE);
  64. DEF_STD(_cerr_sbuf, 2, (streambuf*)_cout_sbuf, _S_CAN_WRITE);
  65.  
  66. DEF_STD(not_open_filebuf, -1, (streambuf*)0, 0);
  67.  
  68. streambuf* streambuf::_list_all = (streambuf*)_cerr_sbuf;
  69.